package com.zhijian.medical.service.impl;

import com.zhijian.medical.dao.local.CommissionAuthorityMapper;
import com.zhijian.medical.entity.po.CommissionAuthority;
import com.zhijian.medical.entity.vo.request.CommissionAuthoritySearchVo;
import com.zhijian.medical.entity.vo.response.CommissionAuthorityVo;
import com.zhijian.medical.service.CommissionAuthorityService;
import com.zhijian.medical.util.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 人员-分级授权书项目业务处理层
 * 
 * @author HCG
 * @version: 1.0
 * @date 2022-03-28 17:07:25
 */
@Slf4j
@Service
public class CommissionAuthorityServiceImpl implements CommissionAuthorityService {

	@Autowired
    private CommissionAuthorityMapper mapper;

    @Override
    public CommissionAuthority selectById(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public CommissionAuthorityVo selectVoById(Long id) {
        return mapper.selectVoById(id);
    }

    @Override
    public void deleteById(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    @Override
    public Long insert(CommissionAuthority commissionAuthority) {
        Date now = new Date();
        commissionAuthority.setCreateTime(now);
        commissionAuthority.setUpdateTime(now);
        return mapper.insert(commissionAuthority) > 0 ? commissionAuthority.getId() : 0L;
    }

    @Override
    public boolean update(CommissionAuthority commissionAuthority) {
        Date now = new Date();
        commissionAuthority.setUpdateTime(now);
        return mapper.updateByPrimaryKey(commissionAuthority) != 0;
    }

    @Override
    public Integer count(CommissionAuthoritySearchVo commissionAuthoritySearchVo) {
        return mapper.count(commissionAuthoritySearchVo);
    }

    @Override
    public List<CommissionAuthorityVo> selectList(CommissionAuthoritySearchVo commissionAuthoritySearchVo) {
        return mapper.selectList(commissionAuthoritySearchVo);
    }

    @Override
    public Page<CommissionAuthorityVo> selectPage(CommissionAuthoritySearchVo commissionAuthoritySearchVo) {
        //先直接查总数
        int count = count(commissionAuthoritySearchVo);
        //分页
        Page<CommissionAuthorityVo> page = new Page<>(true, count, commissionAuthoritySearchVo.getPageNum(), commissionAuthoritySearchVo.getPageSize());
        commissionAuthoritySearchVo.setStartIndex(page.getStartIndex());
        page.setPage(true);
        page.setTotalCount(count);
        List<CommissionAuthorityVo> responseVos = this.selectList(commissionAuthoritySearchVo);
        page.setData(responseVos);
        return page;
    }
    
}